﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using compshop.web.CompShopDataService;
using System.IO;

namespace compshop.web
{
    /// <summary>
    /// Summary description for ImageHandler
    /// </summary>
    public class ImageHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            int id;
            if (!int.TryParse(context.Request.Params["id"], out id))
                return;

            GeneralProduct product = ObjectDataSource.csEntities.GeneralProducts.Where(x => x.GeneralProductID == id).First();
            if (product != null && product.Photo != null)
                context.Response.BinaryWrite(product.Photo);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}